Imports System.IO

Public Class frmNhapDuLieu
    Dim dm As New ExcelDAO

    Private Sub btnDuongDan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDuongDan.Click
        OpenFileDialog1.ShowDialog()
        txtDuongDan.Text = OpenFileDialog1.FileName
    End Sub

    Private Sub btnNhap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNhap.Click
        Try
            Dim ExcelPath As String = txtDuongDan.Text.ToLower()
           
            Dim InsertedTableName As String
            'InsertedTableName = String.Format("select * from [{0}]", cmbChon.Text)
            InsertedTableName = cmbChon.Text
            Dim Ext As String = _
                ExcelPath.Substring(ExcelPath.LastIndexOf(".") + 1)
            If File.Exists(ExcelPath) AndAlso (Ext.Equals("xls") _
                    Or Ext.Equals("xlsx")) Then
                dm.importToServer(OpenFileDialog1.FileName, InsertedTableName)

                MessageBox.Show("File imported successfully")
            End If
        Catch ex As Exception

            MessageBox.Show(ex.Message)
        End Try
    End Sub


    Private Sub btnHuy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHuy.Click
        Me.Close()
    End Sub
End Class